package tools;

import java.util.Vector;

public class ResultDocument {
	private Vector<FalseResult> FPVector = new Vector<FalseResult>();
	private Vector<FalseResult> FNVector = new Vector<FalseResult>();
	
	public void addFP(FalseResult fp)
	{
		FPVector.add(fp);
	}
	public void addFN(FalseResult fn)
	{
		FNVector.add(fn);
	}
	public void addFP(String line)
	{
		FalseResult fp = new FalseResult(line);
		FPVector.add(fp);
	}
	public void addFN(String line)
	{
		FalseResult fn = new FalseResult(line);
		FNVector.add(fn);
	}
	
	public int getRightBoundErrorNum()
	{
		int num = 0;
		for(FalseResult fp : FPVector)
		{
			for(FalseResult fn : FNVector)
			{
				if(fp.beginPos == fn.beginPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
			}
		}
		return num;
	}
	public int getLeftBoundErrorNum()
	{
		int num = 0;
		for(FalseResult fp : FPVector)
		{
			for(FalseResult fn : FNVector)
			{
				if(fp.endPos == fn.endPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
			}
		}
		return num;
	}
	public int getBothBoundErrorNum()
	{
		int num = 0;
		for(FalseResult fp : FPVector)
		{
			for(FalseResult fn : FNVector)
			{
				if(fp.endPos > fn.endPos && fp.beginPos<fn.beginPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
				if(fn.endPos > fp.endPos && fn.beginPos<fp.beginPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
				if(fn.beginPos<fp.beginPos && fp.beginPos<fn.endPos && fn.endPos<fp.endPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
				if(fp.beginPos<fn.beginPos && fn.beginPos<fp.endPos && fp.endPos<fn.endPos)
				{
					num++;
					//System.out.println(fp.toString());
					//System.out.println(fn.toString());
					//System.out.println();
					break;
				}
			}
		}
		return num;
	}
	public int getSingleFPErrorNum()
	{
		int num = 0;
		for(FalseResult fp : FPVector)
		{
			boolean isBoundError = false;
			for(FalseResult fn : FNVector)
			{
				if(!isNoCover(fp,fn))
				{
					isBoundError = true;
					break;
				}
			}
			if(!isBoundError)
			{
				System.out.println(fp.toString());
				num++;
			}
		}
		return num;
	}
	public int getSingleFNErrorNum()
	{
		int num = 0;
		for(FalseResult fn : FNVector)
		{
			boolean isBoundError = false;
			for(FalseResult fp : FPVector)
			{
				if(!isNoCover(fp,fn))
				{
					isBoundError = true;
					break;
				}
			}
			if(!isBoundError)
			{
				//System.out.println(fn.toString());
				num++;
			}
		}
		return num;
	}
	public boolean isNoCover(FalseResult fp, FalseResult fn)
	{
		if(fp.beginPos < fn.beginPos)
		{
			if(fp.endPos < fn.beginPos) return true;
			else return false;
		}else if(fp.beginPos > fn.beginPos)
		{
			if(fp.beginPos > fn.endPos) return true;
			else return false;
		}else
		{
			if(fp.endPos == fn.endPos) return true;
			else return false;
		}
	}
	
	public int getSingleFNErrorNum(int i)
	{
		int num = 0;
		for(FalseResult fn : FNVector)
		{
			boolean isBoundError = false;
			for(FalseResult fp : FPVector)
			{
				if(!isNoCover(fp,fn))
				{
					isBoundError = true;
					break;
				}
			}
			if(!isBoundError)
			{
				
				String[] parts = fn.text.split("\\W+");
				if(parts.length==i)
				{
					//System.out.println(fn.toString());
					num++;
				}
			}
		}
		return num;
	}
	public int getSingleFPErrorNum(int i)
	{
		int num = 0;
		for(FalseResult fp : FPVector)
		{
			boolean isBoundError = false;
			for(FalseResult fn : FNVector)
			{
				if(!isNoCover(fp,fn))
				{
					isBoundError = true;
					break;
				}
			}
			if(!isBoundError)
			{
				String[] parts = fp.text.split("\\W+");
				if(parts.length==i)
				{
					//System.out.println(fn.toString());
					num++;
				}
			}
		}
		return num;
	}
	public int getOneTokenUnrecognizeNum()
	{
		int num=0;
		for(FalseResult fn : FNVector)
		{
			
		}
		
		return num;
	}
	
}
